<?php
include_once("../dao/predio_dao_class.php");
include_once("../model/predio_model_class.php");

//use dao\PredioDAO as DepDao;
//use model\PredioModel as DepModel;

class PredioController{
    
    function cadastrar($campus,$nome){
        
        $pre = new PredioDAO();
        
        if(!$pre->existe($nome,$campus)){
            $preM = new PredioModel();
            $preM->setCampus($campus);
            $preM->setNome($nome);

            return $pre->insert($preM);
        }
        return true;
         
    }
    
    function alterar($id, $campus, $nome){
        
        $preM = new PredioModel();
        $preM->setCampus($campus);
        $preM->setNome($nome);
        $preM->setId($id);
        
        $pre = new PredioDAO();
        
        return $pre->update($preM);
    }
    
    function excluir($id){
        
        $pre = new PredioDAO();
        
        return $pre->delete($id);
    }
    
    function selecionar(){
        $pre = new PredioDAO();
        
        return $pre->findAllPredio();
    }
    
    function selecionarPredioPorId($id){
        $pre = new PredioDAO();
        
        return $pre->findPredioById($id);
    }
    
    function selecionarPrediosPeloCampus($id){
        $pre = new PredioDAO();
        
        return $pre->findPrediosBycampus($id);
    }
    
    function selecionarPrediosPorCampusJSON($id){
        $pre = new PredioDAO();
        
        return $pre->findPrediosBycampusJSON($id);
    }
    
    function selecionarJSON(){
        $pre = new PredioDAO();
        
        return $pre->findAllPredioJSON();
    }
}

//$teste = new PredioController();
//
//if($teste->cadastrar(1, "Quimica")){
//    echo "foi";
//}else{
//    echo "não foi";
//}

